package com.events
{
	import flash.net.URLLoader;

	private var buildFileName:String = "http://servant/xml/"+userid+"/rate.xml";
	private	var fileXMLName:String = buildFileName;
	
	
	
	public class LoadXML
	{
		public function LoadXML()
		{
			var xmlLoader:URLLoader = new URLLoader();
			xmlLoader.addEventListener(Event.COMPLETE, onXmlLoadComplete);
			xmlLoader.load(new URLRequest(fileXMLName));
		}
		
		function onXmlLoadComplete(event:Event):void 
		{
			xmlData = new XML(event.target.data);
			userData = xmlData.user.(@userid == userid);
			rateList = userData.rates;
			for  each( var nameEl:XML in rateList)
			{
				trace(nameEl);
			}	
			
			today = new Date();
			
			rateChildren = rateList.rate.
				(@month == today.month).@value;
			
			
			titleName = userData.titles.title.@name;
			
			titleTime = userData.titles.title.@time;
			
			titleDay = xmlData.month_days.month_day.(@id == today.month).@mon;
			
			var monthValue:XMLList = rateList.rate.(@month == today.month+1 && @year == today.fullYear);
			if (monthValue.length()>0)
			{
				thisRate = monthValue[0].@value;
				currentState="warning";	
			}
			
			var prevMonthNumber:Number = today.month-1; 
			if (prevMonthNumber == -1) 
			{
				prevMonthNumber = 11;	
			}
			previousDate = xmlData.month_days.month_day.
				(@id == prevMonthNumber).@mon;
			dayIs = xmlData.month_days.month_day.(@id == today.month).@mon;
			
			thisYear = xmlData.login.userid.rates.rate.
				(@month == today.month).@year;
		}
		
	}
}
